import { customForm } from '@/components/ProForm/interface/index';
import { Role } from '@/api/interface';

import { defaultStyle } from '@/basic/style';
import { ProTableValue } from '@/interface/public';

export function useAddForm(proTableBox: ProTableValue) {
  let addForm = reactive<customForm<Role.ResRoleList>>({
    form: {},
    title: '',
    visible: false,
    formCols: 1,
    options: [
      {
        label: 'id',
        prop: 'id',
        hide: true,
        type: 'input',
        defaultValue: ''
      },
      {
        type: 'input',
        label: 'roleName',
        hide: false,
        prop: 'roleName',
        defaultValue: '',
        rules: [{ required: true, message: 'roleName', trigger: 'blur' }]
      },
      {
        type: 'input',
        label: 'roleRemark',
        defaultValue: '',
        hide: false,
        prop: 'remark',
        attrs: {
          style: defaultStyle
        }
      }
    ]
  });

  const saveAddForm = async form => {
    form.id ? await roleUpdate(form) : await roleSave(form);

    elMessage();
    addForm.visible = false;
    proTableBox.value?.getTableList();
  };
  return { addForm, saveAddForm };
}
